package com.ydd.config;


import com.ydd.properties.AliOssProperties;
import com.ydd.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-04-15 18:24
 */

/**
 * 配置类，用于创建AliOssUtil对象
 */
@Configuration
@Slf4j
public class AliOSSConfiguration {
    @Bean
    @ConditionalOnMissingBean //如果容器中没有当前这个对象才会运行当前方法将返回值加入spring容器
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){
        log.info("开始创建阿里云文件上传工具类对象:{}",aliOssProperties);
        return new AliOssUtil(
                aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName()
        );

    }
}
